package com.jianbing.north.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.jianbing.common.utils.SecurityUtils;
import com.jianbing.north.domain.NorthUserRecordDTO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jianbing.common.annotation.Log;
import com.jianbing.common.core.controller.BaseController;
import com.jianbing.common.core.domain.AjaxResult;
import com.jianbing.common.enums.BusinessType;
import com.jianbing.north.domain.NorthPart3Record;
import com.jianbing.north.service.INorthPart3RecordService;
import com.jianbing.common.utils.poi.ExcelUtil;
import com.jianbing.common.core.page.TableDataInfo;

/**
 * part3录音文件Controller
 * 
 * @author ruoyi
 * @date 2024-06-22
 */
@RestController
@RequestMapping("/north/part/three")
public class NorthPart3RecordController extends BaseController
{
    @Autowired
    private INorthPart3RecordService northPart3RecordService;

    /**
     * 查询part3录音文件列表
     */
//    @PreAuthorize("@ss.hasPermi('north:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(NorthPart3Record northPart3Record)
    {
        startPage();
        List<NorthPart3Record> list = northPart3RecordService.selectNorthPart3RecordList(northPart3Record);
        return getDataTable(list);
    }

    /**
     * 导出part3录音文件列表
     */
    //  @PreAuthorize("@ss.hasPermi('north:record:export')")
    @Log(title = "part3录音文件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NorthPart3Record northPart3Record)
    {
        List<NorthPart3Record> list = northPart3RecordService.selectNorthPart3RecordList(northPart3Record);
        ExcelUtil<NorthPart3Record> util = new ExcelUtil<NorthPart3Record>(NorthPart3Record.class);
        util.exportExcel(response, list, "part3录音文件数据");
    }

    /**
     * 获取part3录音文件详细信息
     */
    //  @PreAuthorize("@ss.hasPermi('north:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(northPart3RecordService.selectNorthPart3RecordById(id));
    }

    /**
     * 新增part3录音文件
     */
    //  @PreAuthorize("@ss.hasPermi('north:record:add')")
    @Log(title = "part3录音文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NorthPart3Record northPart3Record)
    {
        northPart3Record.setUserId(SecurityUtils.getUserId());
        northPart3Record.setInsertTime(new Date());
        return toAjax(northPart3RecordService.insertNorthPart3Record(northPart3Record));
    }

    /**
     * 修改part3录音文件
     */
    //  @PreAuthorize("@ss.hasPermi('north:record:edit')")
    @Log(title = "part3录音文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NorthPart3Record northPart3Record)
    {
        return toAjax(northPart3RecordService.updateNorthPart3Record(northPart3Record));
    }

    /**
     * 删除part3录音文件
     */
    //  @PreAuthorize("@ss.hasPermi('north:record:remove')")
    @Log(title = "part3录音文件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(northPart3RecordService.deleteNorthPart3RecordByIds(ids));
    }


    /**
     * 获取part3结果汇总
     */
    //   @PreAuthorize("@ss.hasPermi('north:record:query')")
    @GetMapping(value = "/summary")
    public TableDataInfo getInfo()
    {
        startPage();
        Long userId = SecurityUtils.getUserId();
        List<NorthUserRecordDTO> list = northPart3RecordService.selectNorthRecordSummaryList(userId);
        return getDataTable(list);
    }
}
